<?php
class Administrator_Model_Product_Model extends Administrator_Model_System {
	public function __construct() {
		$this->db = Zend_Registry::get ( 'vicdbsystem' );
		$this->lang = new Nguyen_language_system ();
	}
	//////////////product_details//////////////
	public function insertPro_details($name, $image,$cat,$type,$store,$manufact,$price,$currency,$salenb,$salepc,$intro,$attribute,$warranty,$createdate, $status) {
		$data = array ('name' => $name, 'image' => $image,'cat' => $cat,'type' =>$type,'store' =>$store,'manufact' =>$manufact,'price' =>$price,'currency' =>$currency,'salenb' =>$salenb,'salepc' =>$salepc,'intro' =>$intro,'attribute' =>$attribute,'warranty' =>$warranty,'createdate' =>$createdate, 'status' => $status );
		$this->db->insert ( 'pro_details', $data );
		return $this->db->lastInsertId ();
		return  $this->db->lastInsertId();
	}
	public function updatePro_details($id,$name, $image,$cat,$type,$store,$manufact,$price,$currency,$salenb,$salepc,$intro,$attribute,$warranty) {
		$where = "id = '$id'";
		$data = array ('name' => $name, 'image' => $image,'cat' => $cat,'type' =>$type,'store' =>$store,'manufact' =>$manufact,'price' =>$price,'currency' =>$currency,'salenb' =>$salenb,'salepc' =>$salepc,'intro' =>$intro,'attribute' =>$attribute,'warranty' =>$warranty );
		$this->db->update ( 'pro_details', $data, $where );
	}
	// ////// cat /////////////////////////////////
	public function insertPro_cat($name, $image, $type, $status) {
		$data = array ('name' => $name, 'image' => $image, 'type' => $type, 'status' => $status );
		$this->db->insert ( 'pro_cat', $data );
		return $this->db->lastInsertId ();
	}
	public function updatePro_cat($id, $name, $image, $type) {
		$where = "id = '$id'";
		$data = array ('name' => $name, 'image' => $image, 'type' => $type );
		$this->db->update ( 'pro_cat', $data, $where );
	}
	public function delPro_cat($id) {
		$where = "id =  '$id'";
		$this->db->delete ( 'pro_cat', $where );
	}
	// ////// currency /////////////////////////////////
	public function insertPro_currency($name, $display, $value) {
		$data = array ('name' => $name, 'display' => $display, 'value' => $value );
		$this->db->insert ( 'pro_currency', $data );
		return $this->db->lastInsertId ();
	}
	public function updatePro_currency($id, $name, $display, $value) {
		$where = "id = '$id'";
		$data = array ('name' => $name, 'display' => $display, 'value' => $value );
		$this->db->update ( 'pro_currency', $data, $where );
	}
	public function delPro_currency($id) {
		$where = "id =  '$id'";
		$this->db->delete ( 'pro_currency', $where );
	}
	// //////////pro_manufact//////////////////////
	public function insertPro_manufact($name, $image, $website, $status) {
		$data = array ('name' => $name, 'image' => $image, 'website' => $website, 'status' => $status );
		$this->db->insert ( 'pro_manufact', $data );
		return $this->db->lastInsertId ();
	}
	public function updatePro_manufact($id, $name, $image, $website, $status) {
		$where = "id = '$id'";
		$data = array ('name' => $name, 'image' => $image, 'website' => $website, 'status' => $status );
		$this->db->update ( 'pro_manufact', $data, $where );
	}
	// ///////////pro_store/////////////////////////
	public function insertPro_store($name, $image, $address, $phone, $email, $curency, $intro, $status) {
		$data = array ('name' => $name, 'image' => $image, 'address' => $address, 'phone' => $phone, 'email' => $email, 'curency' => $curency, 'intro' => $intro, 'status' => $status );
		$this->db->insert ( 'pro_store', $data );
		return $this->db->lastInsertId ();
	}
	public function updatePro_store($id, $name, $image, $address, $phone, $email, $curency, $intro) {
		$where = "id = '$id'";
		$data = array ('name' => $name, 'image' => $image, 'address' => $address, 'phone' => $phone, 'email' => $email, 'curency' => $curency, 'intro' => $intro);
		$this->db->update ( 'pro_store', $data, $where );
	}
	public function delPro_store($id) {
		$where = "id =  '$id'";
		$this->db->delete ( 'pro_store', $where );
	}
	// ////// tag /////////////////////////////////
	public function insertPro_tag($name) {
		$data = array ('name' => $name );
		$this->db->insert ( 'pro_tag', $data );
		return $this->db->lastInsertId ();
	}
	public function updatePro_tag($id, $name) {
		$where = "id = '$id'";
		$data = array ('name' => $name );
		$this->db->update ( 'pro_tag', $data, $where );
	}
	public function delPro_tag($id) {
		$where = "id =  '$id'";
		$this->db->delete ( 'pro_tag', $where );
	}
	// ////// tag pro /////////////////////////////////
	public function insertPro_tag_pro($tag,$product) {
		$data = array ('tag' => $tag ,'product' => $product );
		$this->db->insert ( 'pro_tag_pro', $data );
		return $this->db->lastInsertId ();
	}
	public function updatePro_tag_pro($id,$tag,$product) {
		$where = "id = '$id'";
		$data = array ('tag' => $tag ,'product' => $product);
		$this->db->update ( 'pro_tag_pro', $data, $where );
	}
	public function delPro_tag_pro($id) {
		$where = "id =  '$id'";
		$this->db->delete ( 'pro_tag_pro', $where );
	}
	// ////// type /////////////////////////////////
	public function insertPro_type($name, $image,$store, $status) {
		$data = array ('name' => $name, 'image' => $image,'store' => $store, 'status' => $status );
		$this->db->insert ( 'pro_type', $data );
		return $this->db->lastInsertId ();
	}
	public function updatePro_type($id, $name, $image,$store) {
		$where = "id = '$id'";
		$data = array ('name' => $name, 'image' => $image,'store' => $store );
		$this->db->update ( 'pro_type', $data, $where );
	}
	////////             tag           /////////////////////////////////
	public function insertTag($name){
		$data = array('name'  => $name);
		$this->db->insert('pro_tag',$data);
		return $this->db->lastInsertId();
	}
	public function GetTagIdByName($name){
		$sql = 'select id from pro_tag where name = "'.$name.'"';
		$result = $this->db->fetchRow($sql);
		return $result['id'];
	}
	public function checkExistTag($name){
		$sql = 'select id from pro_tag where name = "'.$name.'"';
		$result = $this->db->fetchAll($sql);
		if(count($result)>0) return true;
		return false;
	}
	public function insertContentTag($content,$tag){
		$data = array('product'  => $content,'tag'  => $tag);
		$this->db->insert('pro_tag_pro',$data);
		return $this->db->lastInsertId();
	}
	public function deleteContentTagByContent($id){
		$where = "product='".$id."'";
		$this->db->delete('pro_tag_pro',$where);
	}
}